<template>
  <div>
    <v-md-editor
      v-model="editorValue"
      :disabled-menus="[]"
      @upload-image="handleUploadImage"
      height="calc(100vh - 150px)"></v-md-editor>
  </div>
</template>

<script>
    export default {
      name: "mdEditor",
      data() {
        return {
          editorValue: this.content != null ? this.content : "",
        }
      },
      props: {
        // 接收值父组件传递值
        value: String
      },
      methods: {
        // v-md-editor 文件上传
        handleUploadImage(event, insertImage, files) {
          // console.log(files);
          // 上传
          for (let i = 0; i < files.length; i++) {
            this.crud.upload(files[i], "image/vMdEditor/").then(res => {
              // 获取返回数据
              let data = res.data.data;
              // 添加图片到内容
              insertImage({
                url: data.url,
                desc: data.name
              });
            });
          }
        },
        refresh(context){
          console.log('刷新啊', context)
          this.editorValue = context
        }
      },
      watch: {
        value: function (newNum, oldNum) {
          // 修改调用者传入的值
          console.log('newNum', newNum)
          console.log('oldNum', oldNum)
          this.editorValue = newNum
          this.$emit('input', newNum)
        }
      }
    }
</script>

<style scoped>

</style>
